'''
@Author: your name
@Date: 2020-02-05 14:53:30
@LastEditTime : 2020-02-05 15:30:17
@LastEditors  : Please set LastEditors
@Description: In User Settings Edit
@FilePath: \pyqt5\demo_089_QMenu.py
'''
from PyQt5.Qt import *


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle('demo_089_QMenu')
        self.resize(500,500)
        self.setup_ui()

    def setup_ui(self):
        self.模拟菜单()
    
    def 模拟菜单(self):

        btn = QPushButton('File',self)
        menu_file = QMenu(btn)

        new_action = QAction('&New',menu_file)
        new_action.setIcon(QIcon('ico/orange.ico'))
        menu_file.addAction(new_action)
        new_action.triggered.connect(lambda : print('新建按钮被按下了'))

        open_action = QAction('&Open',menu_file)
        open_action.setIcon(QIcon('ico/open.ico'))
        menu_file.addAction(open_action)
        open_action.triggered.connect(lambda : print('打开按钮被按下了'))

        menu_file.addSeparator()

        open_recent_menu = QMenu(menu_file)
        open_recent_menu.setTitle('open recent..')
        file_action = QAction('PyQt-Gui编程.py',open_recent_menu)
        open_recent_menu.addAction(file_action)
        
        menu_file.addMenu(open_recent_menu)
        menu_file.addSeparator()

        
        exit_action = QAction('&Exit',menu_file)
        exit_action.setIcon(QIcon('ico/delete.ico'))
        menu_file.addAction(exit_action)
        exit_action.triggered.connect(lambda : print('退出按钮被按下了'))


        btn.setMenu(menu_file)
        

if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)

    win = Window()
    win.show()
    sys.exit(app.exec_())
